import {SUCCESS_CODE} from '../../src/constants'

const timeout = 1000
const List: {
  username: string
  password: string
  role: string
  roleId: string
  permissions: string | string[]
}[] = [
  {
    username: 'admin',
    password: 'admin',
    role: 'admin',
    roleId: '1',
    permissions: ['*.*.*']
  },
]

export default [{
  url: '/mock/user/login',
  method: 'post',
  timeout,
  response: ({body}) => {
   // console.log('mock', body)
    const data = body
    let hasUser = false
    for (const user of List) {
      if (user.username === data.username && user.password === data.password) {
        hasUser = true
        return {
          code: SUCCESS_CODE,
          data: user
        }
      }
    }
    if (!hasUser) {
      return {
        code: 500,
        message: '账号或密码错误'
      }
    }
  }
}]
